package 每日一题;

import java.util.*;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/uncommon-words-from-two-sentences/
 */
public class _884_两句话中的不常见单词 {
    public String[] uncommonFromSentences(String s1, String s2) {
        Map<String, Integer> freg = new HashMap<>();
        insert(s1, freg);
        insert(s2, freg);

        List<String> ans = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : freg.entrySet()) {
            if (entry.getValue() == 1) {
                ans.add(entry.getKey());
            }
        }
        return ans.toArray(new String[0]);
    }
    private void insert(String s, Map<String, Integer> freg) {
        String[] split = s.split(" ");
        for (String word : split) {
            freg.put(word, freg.getOrDefault(word, 0) + 1);
        }
    }
}
